$(document).ready(function(){ 
	$("#form-add").Validform({
		tiptype : 2,
		showAllError:true,
		datatype: {
              "empty": /^\s*$/,
              "code":/^[a-z0-9A-Z_-]{2,16}$/
              },
		callback : function(form) {
			layer.confirm('您确认提交数据？',function(index){
			    layer.close(index);
			    submit();
			})
			return false;
		}
	}); 
});

submit = function() {
	var adVo = {};
	adVo.desc = $('#desc').val(); 
	adVo.version = $('#version').val();
	var filepath = $('#file').val();
	var extStart = filepath.lastIndexOf(".");
	var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	if (ext != ".MSI" && ext != ".EXE") {
		alert("请选择 .MSI或 .EXE安装文件!");
		return;
	}
	$.ajaxFileUpload({
		type : "POST", 
		url : baseURL + '/api/pcSetup/add',
		secureuri : false,
		fileElementId : 'file',
		data : adVo,
		dataType : 'json',
		success : function(result, status) { 
			if (!result.flag) {
				alert(result.message);
				return;
			}else{
				alert("上传文件成功~~~");
			} 
			layer.closeAll();
			window.parent.location.reload(); 
		},
		error : function(data, status, e) {
			alert(e);
		}
	});
}